package com.madou.dbtool.redis.panel.callback;

import com.madou.common.annotation.HideClass;
import com.madou.dbtool.redis.terminal.RedisTerminal;
import redis.clients.jedis.Connection;
import redis.clients.jedis.JedisMonitor;

/**
 * 监听redis的事件窗口
 * @author miukoo
 */
@HideClass
public class JedisMonitorCallback extends JedisMonitor implements Runnable {
    volatile Connection client;
    RedisTerminal redisTerminal;

    public JedisMonitorCallback(RedisTerminal redisTerminal){
        this.redisTerminal = redisTerminal;
    }

    @Override
    public void onCommand(String command) {
       redisTerminal.addInputChar(command);
    }

    @Override
    public void run() {
        this.redisTerminal.getRedisSourceManager().monitor(this);
    }

    /**
     * 关闭窗口
     */
    public void desroty(){
        if(this.client!=null){
            this.client.disconnect();
            this.client.close();
        }
    }
}